﻿using Common;
using Logic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Model;
using System;

namespace AppAdmin
{
    public class ClientsDataController : BaseController
    {
        [HttpGet]
        public ActionResult GetClientsDataJson()
        {
            var data = new
            {
                dataItems = this.GetDataItemList(),
                organize = this.GetOrganizeList(),
                role = this.GetRoleList(),
                duty = this.GetDutyList(),
                user = "",
                authorizeMenu = this.GetMenuList(),
                authorizeButton = this.GetMenuButtonList(),
            };
            return Content(data.ToJson());
        }
        private object GetDataItemList()
        {
            Dictionary<string, object> dictionaryItem = new Dictionary<string, object>();
            //var itemdata = new ItemsDataLogic().GetList();
            //List<Sys_Items> list_Type = new ItemsTypeLogic().GetList();
            //foreach (var item in list_Type)
            //{
            //    var dataItemList = itemdata.FindAll(t => t.F_ItemId != null && t.F_ItemId.Equals(item.F_Id));
            //    Dictionary<string, string> dictionaryItemList = new Dictionary<string, string>();
            //    foreach (var itemList in dataItemList)
            //    {
            //        dictionaryItemList.Add(itemList.F_ItemCode, itemList.F_ItemName);
            //    }
            //    dictionaryItem.Add(item.F_EnCode, dictionaryItemList);
            //}
            return dictionaryItem;
        }
        private object GetOrganizeList()
        {
            Dictionary<string, object> dictionary = new Dictionary<string, object>();
            //SysAdmin db = new SysAdmin();
            //var data =db.Sys_Organize.ToList();
            //foreach (Sys_Organize item in data)
            //{
            //    var fieldItem = new
            //    {
            //        encode = item.F_EnCode,
            //        fullname = item.F_FullName
            //    };
            //    dictionary.Add(item.F_Id, fieldItem);
            //}
            return dictionary;
        }
        private object GetRoleList()
        {
            Dictionary<string, object> dictionary = new Dictionary<string, object>();
            //SysAdmin db = new SysAdmin();
            //var data =db.Sys_Role.ToList();
            //foreach (Sys_Role item in data)
            //{
            //    var fieldItem = new
            //    {
            //        encode = item.F_EnCode,
            //        fullname = item.F_FullName
            //    };
            //    dictionary.Add(item.F_Id, fieldItem);
            //}
            return dictionary;
        }
        private object GetDutyList()
        {
            //DutyApp dutyApp = new DutyApp();
            //var data = dutyApp.GetList();
            //Dictionary<string, object> dictionary = new Dictionary<string, object>();
            //foreach (RoleEntity item in data)
            //{
            //    var fieldItem = new
            //    {
            //        encode = item.F_EnCode,
            //        fullname = item.F_FullName
            //    };
            //    dictionary.Add(item.F_Id, fieldItem);
            //}
            //return dictionary;
            return new object();
        }
        private object GetMenuList()
        {
            try
            {
                //var roleId = OperatorProvider.Provider.GetCurrent().RoleId;
                //return ToMenuJson(new RoleAuthorizeApp().GetMenuList(roleId), "0");
                return ToMenuJson(new Model1Container().Sys_Module.ToList(), "0");
            }
            catch (Exception ex)
            {

            }
            return null;
        }
        private string ToMenuJson(List<Sys_Module> data, string parentId)
        {
            StringBuilder sbJson = new StringBuilder();
            sbJson.Append("[");
            List<Sys_Module> entitys = data.FindAll(t => t.F_ParentId == parentId);
            if (entitys.Count > 0)
            {
                foreach (var item in entitys)
                {
                    string strJson = item.ToJson();
                    strJson = strJson.Insert(strJson.Length - 1, ",\"ChildNodes\":" + ToMenuJson(data, item.F_Id) + "");
                    sbJson.Append(strJson + ",");
                }
                sbJson = sbJson.Remove(sbJson.Length - 1, 1);
            }
            sbJson.Append("]");
            return sbJson.ToString();
        }
        private object GetMenuButtonList()
        {
            //var roleId = OperatorProvider.Provider.GetCurrent().RoleId;
            //var data = new RoleAuthorizeApp().GetButtonList(roleId);
            //var dataModuleId = data.Distinct(new ExtList<ModuleButtonEntity>("F_ModuleId"));
            //Dictionary<string, object> dictionary = new Dictionary<string, object>();
            //foreach (ModuleButtonEntity item in dataModuleId)
            //{
            //    var buttonList = data.Where(t => t.F_ModuleId.Equals(item.F_ModuleId));
            //    dictionary.Add(item.F_ModuleId, buttonList);
            //}
            //return dictionary;
            return new object();
        }
    }
}
